package novemberBot.sensor;

import novemberBot.FactoryFloorRobot;
import novemberBot.communication.RS485Responder;
/**basically a remote for the LSPollerClass simulates the effect of having the sensor on the same brick
 * @author Antoine Lennartz*/
public class RightLineChecker implements LineChecker, RS485Responder {

	private final byte RSID=1;
	
	/**status boolean*/
	private boolean onLine=false;
	/**lock for status boolean*/
	private Object statusLock = new Object();
	
	private boolean enable=false;
	
	/**default Constructor*/
	public RightLineChecker(){
		FactoryFloorRobot.getInstance().getConnectionManager().addResponder(this);
	}
	
	
	@Override
	public boolean onLine() {
		synchronized(statusLock){
			//if (onLine) Debugger.audibleDebug(800, 100);
			return onLine;
		}
	}



	@Override
	public byte getRSId() {
		return RSID;
	}



	@Override
	public void newRS485Data(byte[] data) {
		if(enable){
			if(data[0]==1) setOnLine(true);
			else if(data[0]==0) setOnLine(false);
		}
		
	}
	/**synchronized mutator for status boolean
	 * @param onLine - new value for onLine*/
	private void setOnLine(boolean onLine){
		synchronized(statusLock){
			this.onLine=onLine;
		}
	}
	@Override
	public void setEnable(boolean enable){
		this.enable=enable;
	}
}
